package group.program.register.email;

import group.program.Controller.RegisterController;
import group.program.Service.RegisterService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class exist {

    @InjectMocks
    private RegisterController registerController;

    @Mock
    private RegisterService registerService; // 创建一个对 RegisterService 的 mock 实例

    @BeforeEach
    void setUp() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    void testExistEmail() {
        String existEmail = "jason12345@qq.com";

        // 模拟 registerService 中的方法
        when(registerService.isEmailExist(existEmail)).thenReturn("邮件地址已存在");

        assertEquals("邮件地址已存在", registerController.checkIfEmailExists(existEmail));
    }

    @Test
    void testNoExistEmail() {
        String noExistEmail = "test@test.com";

        // 模拟 registerService 中的方法
        when(registerService.isEmailExist(noExistEmail)).thenReturn(null);

        assertNull(registerController.checkIfEmailExists(noExistEmail));
    }
}

